package com.chandra.pos.payment.web;


import com.chandra.pos.common.web.POSController;
import com.chandra.pos.payment.model.PaymentFilter;
import com.chandra.pos.payment.model.PaymentList;
import com.chandra.pos.payment.model.PaymentModel;
import com.chandra.pos.payment.service.PaymentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by Admin on 7/2/14.
 */
@Controller
@RequestMapping("payment")
public class PaymentController extends POSController {


    private static String PAGE_MODULE = "payments";

    Logger logger = LoggerFactory.getLogger(PaymentController.class);

    @Autowired
    PaymentService paymentService;


    public PaymentController() {
        this.setTabIndex(6);

    }


    @RequestMapping(value = "/home", method = RequestMethod.GET)
    public String index(PaymentModel model) {

        return getPageView(PAGE_MODULE, PAGE_HOME);

    }

    @RequestMapping(value = "/search", method = RequestMethod.GET)
    public
    @ResponseBody
    PaymentList search(PaymentFilter model) {

        return paymentService.search(model);

    }

    @RequestMapping(value = "/new", method = RequestMethod.GET)
    public String newPayment(PaymentModel model) {

        return getPageView(PAGE_MODULE, PAGE_NEW);

    }


    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public
    @ResponseBody
    PaymentModel savePayment(PaymentModel newPayment) {

        return newPayment = paymentService.saveCustomerPayment(newPayment);


    }


}
